package com.jiepu.daily.corejava.advanceed.part2.day0721.test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @Description:
 * @author: xinjie.txt
 * @date: 2020/7/21  16:46
 */
public class DoubleColorBall {

	public static void main(String[] args) {

		test1();
		test2();

	}


	// 数组+随机数
	private static void test1() {
		int[] balls = new int[6];

		for (int i = 0; i < 6; i++) {
			int random = (int) (Math.random() * 33 + 1);
			// 去重         exist 重复标记
			boolean exist = false;
			for (int j = 0; j < i; j++) {
				if (balls[j] == random) {
					// 重复，重新生成随机数
					exist = true;
					break;
				}
			} // for j

			if (exist) {
				// 本轮循环作废
				i--;
			} else {
				balls[i] = random;
			} // fi

		} // for i
		System.out.println("Red ball: ");
		System.out.println(Arrays.toString(balls));

		System.out.println("Blue ball: ");
		System.out.println((int) Math.random() * 16 + 1);


	} // test1

	private static void test2() {
		Set set = new HashSet();
		while (set.size() < 6) {
			set.add((int) (Math.random() * 33 + 1));
		}
		System.out.println(Arrays.toString(set.toArray()));
	} // test 2
}
